<template>
  <div class="container contract-review mb70">
    <p class="bread">
      <a href="#/index/cm-law-list" class="font-s-18" v-show="this.$route.query.type==='chief'">首席监控师-法律服务订单</a>
      <a href="#/index/law-order-manage" class="font-s-18" v-show="this.$route.query.type==='business'">业务管理部-法律服务订单</a>
      <a href="#/index/law-notice" class="font-s-18" v-show="this.$route.query.type==='lawNotice'">业务管理部-法律服务通知</a>
    </p>
    <div class="bg-c-fff box-border">
      <h3 class="tm-title">法律服务订单详情</h3>
      <step :stepData="stepData" :stepNum="stepNum" @stepRouter="stepRouter"></step>
    </div>
    <div class="content bg-c-fff">
      <h3 class="tc">交易监控流程图</h3>
      <div class="progress-box rel">
        <company-name-container :companyNames="companyNames"></company-name-container>
        <div class="line" :class="{center: companyNames.length===2}" :style="{height: (events.length+0.5)*90+60+'px'}" v-show="events.length">
          <div class="arrow"></div>
        </div>
        <event-item v-for="(item,index) in events" :key="index" :pstate="item.state" :totalSides="companyNames.length" :side="item.side" :content="item.content" :files="item.files" :eventId="item.id" :isCheck="true" :serviceId="id" :tradeType="'law'" :allState="state"></event-item>
      </div>
      <p class="tc">交易监控结束</p>
    </div>
  </div>
</template>
<script type="text/javascript">
import Step from '../components/Step'
import CompanyNameContainer from '../components/CompanyNameContainer'
import EventItem from '../components/EventItem'
export default {
  components: {
    Step,
    CompanyNameContainer,
    EventItem
  },
  data() {
    return {
      stepNum: 2,
      stepData: [{
        name: '法律服务通知单'
      }, {
        name: '绘制流程图'
      }, {
        name: '法律服务监控'
      }, {
        name: '服务完成'
      }],
      companyNames: [],
      events: [],
      state: 0
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this.getEvents()
  },
  methods: {
    message() {
      this.addEventShow = true
    },
    getEvents() {
      this.$http.get('/legalService/read/detail', {
        params: {
          id: this.id
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.state = data.data.data.status
          this.companyNames = [{ name: data.data.data.customerName }, { name: data.data.data.lawyerName + '律师' }]
          data.data.data.eventList.forEach(item => {
            let event = {}
            event.content = item.content
            event.side = item.memberOrder
            event.state = item.status
            event.files = item.fileList || []
            event.index = item.order
            event.id = item.id
            this.events.push(event)
          })
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    stepRouter(i, name) {
      this.$http.get('/legalService/read/detail', {
        params: {
          id: this.$route.query.id
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          if (i === 0 && data.data.data.status >= 2) {
            this.$router.push('/cm-law-notice?type=' + this.$route.query.type + '&id=' + this.$route.query.id)
          }
          if (i === 1 && data.data.data.status >= 2) {
            this.$router.push('/cm-law-drawing?type=' + this.$route.query.type + '&id=' + this.$route.query.id)
          }
          if (i === 2 && data.data.data.status >= 3) {
            this.$router.push('/cm-law-monitor?type=' + this.$route.query.type + '&id=' + this.$route.query.id)
          }
          if (i === 3 && data.data.data.status >= 4) {
            this.$router.push('/cm-law-complete?type=' + this.$route.query.type + '&id=' + this.$route.query.id)
          }
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    }
  }
}

</script>
<style type="text/css" scoped>
.content {
  padding-bottom: 30px;
  margin-top: 20px;
}

.content h3 {
  line-height: 40px;
  border-bottom: 1px solid #ddd;
}

.line {
  position: absolute;
  width: 2px;
  top: 0;
  left: 65px;
  margin-top: 10px;
  background-color: #cfcfcf;
}

.line.center {
  left: 50%;
}

.line .arrow {
  position: absolute;
  bottom: -10px;
  left: -7px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid #cfcfcf;
}

.content p {
  margin-top: 50px;
}

</style>
